package com.wzy.sort8;

import java.util.Arrays;

/**
 * @author wzy
 * @Date: 2022/1/30 13:23
 * @Description: 选择排序
 */
public class XvanZe {
    public static void main(String[] args) {
        int[] nums = {5, 1, 8, 2, 6, 7, 3, 4};
        int index;
        for (int i = 0; i < nums.length; i++) {
            // 新的趟数  重新赋值为0
            index = 0;
            for (int j = 0; j < nums.length - i; j++) {
                if (nums[j] > nums[index]) {
                    index = j;
                }
            }
            // 交换
            swap(nums, index, nums.length - i - 1);
        }
        System.out.println(Arrays.toString(nums));
    }

    public static void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i] = nums[j];
        nums[j] = temp;
    }
}
